This page last changed on Jul 29, 2006 by scytacki.

One part of the current design is to have a generic whitespace model that can work for any type of configuration file. The purpose of this model is to link the emf model of the configuration file with the text of the file itself.

There are two ways to do this:

  1. store character pos in the text file for each whitespace element
  2. store the ful text of each part of the file in the whitespace model.

I'm going to try the first approach.

So what are the elements of the model. Using the language of the MDA (model driven architecture), it is an instance mapping. Using "marks" to indicate how a model element should be represented in the text.

The elements that need to mapped will be instances of instances of the ecore kernel.
The ecore kernel is:

  • EClass
  • EReference
  • EAttribute

Simple example file:

property1=red
property2=blue
property3=green

The model could be, a Single EClass that represents the whole file. And this eclass has three properties. In java this would have an interface like:

interface SimpleExample{
String getProperty1();
String getProperty2();
String getProperty3();
}

In emf this would be something like:

SimpleExample : EClass
   property1 : EAttribute
   property2 : EAttribute
   property3 : EAttribute

This is still just what is known as the "core" model. It defines the types of objects. So there would be one of these core models for each type of config file. A particular config file would map to an instance of this core model. So using the simple example above it would be more like:

MyFile : SimpleExample
  red : property1
  blue : property2
  green : property3

Mapping

So given a particular instance of a particular core model, we need to map that instance to a text file. Lets start with:
For each EObject in the instance model. There will be a begining and end marker. There will also be set of white space markers. The start and end index of the objectName. To handle an xml like markup for config files there also needs to be an index for the openElementStart and openElementEnd and closeElementStart and closeElementEnd. And the attributesStart and attributesEnd markers. The body is between the openElementEnd and closeElementStart.

EModelElementLocation
 EObject objRef
 Postion position
 Postion namePosition

EObjectLocation -> EModelElementLocation
 EObject objRef
 Postion openElementPosition
 Postion attributesPosition
 Postion closeElementPosition

EStructuralFeatureLocation -> EModelElementLocation
 EStructuralFeature feature

EAttributeLocation -> EStructuralFeatureLocation
 Postion valuePosition
 Postion assignmentPosition

This model doesn't yet deal with EReferences, or lists of attributes or references.

Uses of Whitespace Model

With this whitespace model and the text, and the emf model. What can you do?

  • structured model editing - inorder to simply change values in the model and then update the text file while maintaining the current formatting.
  • selection highlighting - the emf model can be used for the outline view. Then selections in this model can highlight the appropriate text ranges.
  • syntax highlighting - element names can be highlighted in one color and values in another color.
  • error notification? - that is actually the job of the parser.

How to combine this with the standard emf editors.

Any change to the emf model elements needs to be reflected in the text file. Adding observers for this is straight forward in emf. The easiest events to handle would be value change events. In response to this type of event the text editor syntax can be used to replace the current value with the new value. This can be done using the the text document model behind the text editor.

Demo Steps

  • Learn about eclipse editor document positions
  • Make the whitespace emf model, using these positions instead of ints
  • make simple emf model for a property file
  • make instance of this model, and instance of whitespace model to go with it
  • make a new edit view (read only), that displays the text file, and updates it when values in the model change
  • make a JTree parser that can generate the emf model, and whitespace model from a property file.
  • update edit view to reparse the document when it is changed and update the models.
  • make a emf Resource that serializes to the text file format.

Demo Research Questions

  • How do document positions work?
    • They are called Positions. And they are updated by an instance of IPostionUpdater. The postion has a start and offset. They cannot be serialized directly, but they can be treated as a type. Once the document is created these position objects need to be added to the document. Also, if a new position is created it should be added to the document. Most likely new positions will be created in the context of document changes, or new element additions. In these cases the document will need to be updated anyhow, so adding the postions can be done at the same time.
  • How can the whitespace model be introspected at runtime?
    • If it is in separate resource, then that resource will be visible by the standard emf editor. Or if it is in a separate file then that file can be opened. However with separate file approach the changes won't be immediately visible.

Demo Notes

  • the emf editor for the model can be the reflective editor, this makes it easy to plugin new models. This editor can be
    tracked down by looking at the simple reflective editor in the org.eclipse.emf.ui.editor plugin.

Links

http://devresource.hp.com/drc/technical_white_papers/eclipeditor/index.jsp- example of making text editor for eclipse
http://dev.eclipse.org/newslists/news.eclipse.modeling/msg00048.html thread about the eclipse Textual Modeling Framework. And related projects.

Document generated by Confluence on Jan 27, 2014 16:56